﻿Imports AjaxControlToolkit
Imports System.IO


Public Class UT9000P
    Inherits System.Web.UI.Page

    Private Const TARGET_DIR As String = "~/"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then

        Else

        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sTargetDir As String = Request.MapPath(TARGET_DIR)
        System.Diagnostics.Debug.Assert(Directory.Exists(sTargetDir))

        Dim objDisplay As New StringBuilder()
        objDisplay.Append("<h3>You have just saved:</h3><ul>")


        For i As Integer = 0 To Request.Files.Count - 1
            Dim objFile As HttpPostedFile = Request.Files(i)

            If ((objFile.ContentLength > 0) And (objFile.FileName.Length > 0)) Then

                Dim sFileName As String = Path.GetFileName(objFile.FileName)
                Dim sFilePath As String = Path.Combine(sTargetDir, sFileName)
                Dim objFileInfo As New FileInfo(sFilePath)

                If objFileInfo.Exists Then
                    'objFileInfo.Attributes = CType(objFileInfo.Attributes + FileAttributes.ReadOnly, FileAttributes)
                    'objFileInfo.Delete()
                End If

                objFile.SaveAs(sFilePath)

                objDisplay.AppendFormat("<li><a href=""{0}"">{1}</a></li>", _
                    Me.ResolveUrl(Path.Combine(TARGET_DIR, sFileName)), _
                    sFileName)
            End If

        Next

        'objDisplay.Append("</ul>")
        'litDisplay.Text = objDisplay.ToString()
    End Sub
End Class